package ru.sut.excel.parse;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

/**
 *
 * @author pol
 */
public class ReadExcelFile {

    /**
     *
     * @param fileName
     * @return
     */
    public static ArrayList<String> readExcelFile(String fileName) {
        ArrayList<String> excelText = new ArrayList<String>();
        try {
            FileInputStream input = new FileInputStream(fileName);
            POIFSFileSystem fileSystem = new POIFSFileSystem(input);
            HSSFWorkbook workBook = new HSSFWorkbook(fileSystem);
            HSSFSheet sheet = workBook.getSheetAt(0);
            for (Row row : sheet) {
                for (Cell cell : row) {
                    if (!cell.toString().isEmpty()) {
                        excelText.add(cell.toString());
//                        System.out.println(cell.toString());
                    }
                }
            }
        } catch (Exception io) {
        }
        return excelText;
    }
}
